﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArithmeticExpressionCalculator
{
    public class Operands
    {
        string str;
        int position;
        public Operands(string str, int position)
        {
            this.str = str;
            this.position = position;
        }
        public double GetLeftOperand(out int left_boundary)
        {
            int current_position = position - 1;
            while (str[current_position] != '/' && str[current_position] != '*' && str[current_position] != '+' && str[current_position] != '-' && current_position != 0)
                current_position--;
            if (str[current_position] == '*' || str[current_position] == '/')
                current_position++;
            string left_argument = str.Substring(current_position, position - current_position);
            left_boundary = current_position;
            return Convert.ToDouble(left_argument);
        }
        public double GetRightOperand(out int right_boundary)
        {
            int current_position = position + 1;
            if (str[current_position] == '+' || str[current_position] == '-') current_position++;

            while (str[current_position] != '/' && str[current_position] != '*' && str[current_position] != '+' && str[current_position] != '-' && current_position != str.Length - 1)
                current_position++;
            if (current_position != str.Length - 1) current_position--;
            string right_argument = str.Substring(position + 1, current_position - position);
            right_boundary = current_position;
            return Convert.ToDouble(right_argument);
        }
    }
}
